import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        token: ''

    },
    mutations: {
        login(state, token) {
            this.state.token = token;
            localStorage.setItem("token", token);
            console.log(token.toString())
        },
        initToken(state) {
            console.log("-------------initToken");
            let token = localStorage.getItem("token");
            if (token === null) {
                localStorage.setItem("token", "");
                token = "";
            }
            this.state.token = token;
        }
    },
    getters: {
        token: state => state.token
    },
    actions: {},
});

